<template>
  <div class="wrap">
    <div class="main">
      <div class="cover">
        <cover-image class="cover-image" :src="mediaInfo.cover" size="@300w_400h" />
      </div>
      <div class="content">
        <div class="title">{{ mediaInfo.title }}</div>
        <div class="count">
          <span class="view"><i class="fa fa-bofangshu"></i> {{ views }}</span>
          <span class="fav"><i class="fa fa-heart"></i> {{ favorites }}</span>
        </div>
        <div class="state">{{ detailData.newestEp.desc }}</div>
        <div class="desc" :class="{expand: isExpand}" @click="handleExpand">
          <span class="btn"><i class="fa" :class="[isExpand ? 'fa-dropup':'fa-dropdown']"></i></span>
          {{ mediaInfo.evaluate }}
        </div>
        <div class="score">
          <span class="rating"><em>{{ score }}</em></span>
          <span class="num">{{ ratingCount }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { reactive, computed, toRefs } from 'vue'
import CoverImage from '@/components/CoverImage'
import { formatNumber } from '@/utils'
export default {
  name: 'BangumiInfo',
  components: {
    CoverImage
  },
  props: {
    detailData: {
      type: Object
    }
  },
  setup(props) {

    const params = reactive({
      isExpand: false,
      mediaInfo: computed(() => props.detailData?.mediaInfo ?? {}),
      stat: computed(() => props.detailData?.seasonStat ?? {}),
      views: computed(() => formatNumber(params.stat?.views ?? 0)),
      favorites: computed(() => formatNumber(params.stat?.favorites ?? 0)),
      pubInfo: computed(() => props.detailData?.pubInfo ?? {}),    
      rating: computed(() => props.detailData?.mediaRating ?? {}),
      score: computed(() => {
        return params.rating.score ? `${params.rating.score}分` : '暂无评分'
      }),
      ratingCount: computed(() => {
        return params.rating.count ? `${params.rating.count}人` : (params.pubInfo.is_started === 0 ? '未开播' : '评分人数不足')
      })
    })

    const handleExpand = () => {
      params.isExpand = !params.isExpand
    }

    return {
      ...toRefs(params),
      handleExpand
    }
  }
}
</script>

<style lang="scss" scoped>
.wrap{
    display: flex;
    flex-direction: column;
    padding: 10px;
    @include border1px (#e7e7e7, 0 0 1px 0)
  }
  .main {
    display: flex;
  }
  .cover{
    width: 75px;
    height: 100px;
    margin-right: 10px;
    &-image {
        padding-bottom: (100 / 75)*100%;
    }
  }
  .content{
    position: relative;
    flex: 1;
    color: $color-text-secondary;
    font-size: 12px;
  }
  .title{
    width: 200px;
    height: 20px;
    font-size: 16px;
    color: $color-text-primary;
    @include max-lines(1);
  }
  .count {
    margin-bottom: 5px;
    .fa {
      font-size: 12px;
    }
    .view{
      margin-right: 10px;
    }
  }
  .state{
    margin-bottom: 5px;
  }
  .desc{
    position: relative;
    padding-right: 16px;
    line-height: 16px;
    @include max-lines(3);
    .btn {
      position: absolute;
      right: 0;
      top: 0;
      .fa{
        font-size: 16px;
      }
    }
    &.expand{
      display: block;
    }
  }
  .score{
    position: absolute;
    right: 0;
    top: 0;
    width: 70px;
    display: flex;
    align-items: center;
    flex-direction: column;
    font-size: 12px;
    color: $color-text-secondary;
    white-space: nowrap;
  }
  .rating{
    color: #ffa726;
    margin-bottom: 7px;
    em{
      margin-right: 3px;
      font-size: 18px;
      font-style: normal;
      white-space: nowrap;
    }
  } 
</style>